package com.lz.service.impl;

import com.lz.domain.TblApplicationInfo;
import com.lz.mapper.TblApplicationInfoDao;
import com.lz.service.TblApplicationInfoService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TblApplicationInfo)表服务实现类
 *
 * @author makejava
 * @since 2024-04-14 14:38:28
 */
@Service("tblApplicationInfoService")
public class TblApplicationInfoServiceImpl implements TblApplicationInfoService {
    @Resource
    private TblApplicationInfoDao tblApplicationInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param applyId 主键
     * @return 实例对象
     */
    @Override
    public TblApplicationInfo queryById(String applyId) {
        return this.tblApplicationInfoDao.queryById(applyId);
    }

    @Override
    public List<TblApplicationInfo> queryAll() {
        return tblApplicationInfoDao.queryAll();
    }

    /**
     * 分页查询
     *
     * @param tblApplicationInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TblApplicationInfo> queryByPage(TblApplicationInfo tblApplicationInfo, PageRequest pageRequest) {
        long total = this.tblApplicationInfoDao.count(tblApplicationInfo);
        return new PageImpl<>(this.tblApplicationInfoDao.queryAllByLimit(tblApplicationInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tblApplicationInfo 实例对象
     * @return 实例对象
     */
    @Override
    public TblApplicationInfo insert(TblApplicationInfo tblApplicationInfo) {
        this.tblApplicationInfoDao.insert(tblApplicationInfo);
        return tblApplicationInfo;
    }

    /**
     * 修改数据
     *
     * @param tblApplicationInfo 实例对象
     * @return 实例对象
     */
    @Override
    public TblApplicationInfo update(TblApplicationInfo tblApplicationInfo) {
        this.tblApplicationInfoDao.update(tblApplicationInfo);
        return this.queryById(tblApplicationInfo.getApplyId());
    }

    /**
     * 通过主键删除数据
     *
     * @param applyId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String applyId) {
        return this.tblApplicationInfoDao.deleteById(applyId) > 0;
    }
}
